package com.videoshare.user;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import org.apache.commons.logging.*;

import com.sapientia.user.UserConstants;

public class UserLogoffAction extends Action
{
	private static Log log = LogFactory.getLog(UserLogoffAction.class);
	
	public ActionForward execute(
			ActionMapping mapping,
			ActionForm form,
			HttpServletRequest request,
			HttpServletResponse response) throws Exception
	{
		HttpSession session = request.getSession();
		UserLoginForm userForm = (UserLoginForm) session.getAttribute(UserConstants.USER_KEY);
		
		if( userForm != null )
		{
			System.out.println("username: " + userForm.getUserName());
			
			session.removeAttribute(UserConstants.USER_KEY);
	        session.invalidate();
	        
	        return mapping.findForward("success");
		}
		else
		{
			//user not logged on
			return mapping.findForward("failure");
		}
		
		
	}
}
